package com.deeper.customview.ui.c1.demo;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.deeper.customview.BaseFragment;
import com.deeper.customview.R;

public class Chapter01Demo09Fragment extends BaseFragment {

    private ImageView iv;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_chapter01_demo09, container, false);

        iv = root.findViewById(R.id.iv);
        Bitmap bmp = Bitmap.createBitmap(500, 800, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bmp);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.FILL);

        paint.setColor(Color.BLACK);
        Path path1 = new Path();
        path1.addRect(20, 20, 150, 150, Path.Direction.CW);

        paint.setColor(Color.RED);
        Path path2 = new Path();
        path2.addCircle(150, 150, 50, Path.Direction.CW);

//        path2.op(path1, Path.Op.DIFFERENCE);
//        path2.op(path1, Path.Op.INTERSECT);
//        path2.op(path1, Path.Op.REVERSE_DIFFERENCE);
//        path2.op(path1, Path.Op.UNION);
        path2.op(path1, Path.Op.XOR);

        canvas.drawPath(path2, paint);
        iv.setImageBitmap(bmp);
        return root;
    }
}
